# -*- coding: utf-8 -*-
# https://www.runoob.com/w3cnote/python3-subprocess.html

import subprocess
import os

# def runcmd(command):
#     ret = subprocess.run(command,shell=True,stdout=subprocess.PIPE,
#     stderr=subprocess.PIPE,encoding="utf-8",timeout=1)
#     if ret.returncode == 0:
#         print("success:",ret)
#     else:
#         print("error:",ret)
#
# print(os.getcwd())
# runcmd('ls')
# runcmd("exit 1")



# https://o-u-u.com/?p=2170bprocess

# def TestPopen():
#     import subprocess
#     p = subprocess.Popen("ls", shell=True)
#     for i in range(250):
#         print("other things")

def TestWait():

  import subprocess
  import datetime
  print (datetime.datetime.now())
  p=subprocess.Popen("sleep 10", shell=True)
  p.wait()                                            # 有p.wait(),第二句print (datetime.datetime.now())等待10s执行，如果没有立刻执行
  print (p.returncode)
  print (datetime.datetime.now())


# TestPopen()

TestWait()